package com.learn.springmvc.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServlet;

@Controller("/go")
public class GoController {

    private final Log logger = LogFactory.getLog(GoController.class);

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String head(HttpServlet servlet) {
        String contextConfigLocation = servlet.getServletContext().getInitParameter("contextConfigLocation");
        logger.info(contextConfigLocation);
        String servletConfig = servlet.getServletConfig().getInitParameter("contextConfigLocation");
        logger.info(servletConfig);
        return "";
    }

    @RequestMapping(value = {"/index", "/"}, method = RequestMethod.GET)
    public String index(Model model) {
        logger.info("--> processed by index");
        model.addAttribute("msg", "go go go!");
        return "";
    }

}
